package com.bytes32.parsing;

import org.apache.hadoop.io.Writable;

import com.bytes32.classification.tree.dataset.AttributeType;
import com.bytes32.classification.tree.dataset.FeatureType;
/**
 * Attempts to convert from a string into 
 * another writable that can be mapped to {@link AttributeType}
 * 
 * Keep this with the default constructor, anything else will fail
 * @author murariuf
 *
 * @param <T>
 */
public interface Parser<FROM> extends Comparable<Parser<? super FROM>>{
	/**
	 * Use any parsing function to move any
	 * value to a more relevant Numeric representation 
	 * Keep parsing simple and efficient
	 * @param value
	 * @return
	 *  a {@link Writable}
	 * @throws
	 * {@link ParsingException}
	 * when you cannot parse into a number
	 */
	Number intoNumber(FROM value) throws ParsingException;
	
	/**
	 * Use any parsing function to move any
	 * value to a more relevant representation as a String
	 * @param value
	 * @return
	 * @throws ParsingException
	 */
	String intoText(FROM value) throws ParsingException;
	
	/**
	 * Increments and returns the current weight of the parser
	 * @return
	 *  incremented weight
	 */
	int incrementWeight();
	
	/**
	 * Returns the current weight of the parser
	 * @return
	 */
	int getWeight();
	
	/**
	 * Returns the attribute type for this parser
	 * @return
	 */
	AttributeType getAttributeType();
	
	/**
	 * Returns the feature type for this parser
	 * @return
	 */
	FeatureType getFeatureType();
	
	/**
	 * Resets the weight of the parsers
	 */
	void reset();
	
	/**
	 * Sets the id of the parser
	 * TODO: also solves the comparison if weight is equal
	 * @param id
	 */
	void setId(int id);
	
	/**
	 * returns the id of the parser
	 * @return
	 */
	int getId();
}
